<link rel="stylesheet" href="/css/publication/publication.css">
<script type="text/javascript" src="/js/publication/publicationrefresh.js"></script>
<script type="text/javascript">
    $(function() {
        $( "a", ".btnResearchSelection" ).button();
        $(".tdMore").button();
    });
</script>

<?php if( $researchList->count() == 0): ?>
    <table class="tbPublicationData" cellpadding="0" cellspacing="0" >
        <tr>
            <td class="tdPublicationDetailTitle">
                <span>No Document(s) or Dataset(s) Found</span>
            </td>
        </tr>
    </table>
    <script type="text/javascript" >
        $('#tdMorePublications').attr('style', 'display:none');
    </script>
<?php else: ?>
    <script type="text/javascript" >
        $('#tdMorePublications').attr('style', 'display:block');
    </script>
<?php endif; ?>

<?php foreach ($researchList as $research):?>

<table class="tbPublicationData" cellpadding="0" cellspacing="0" width="100%">
    <tr>
        <td class="tdPublicationDetailContributor" colspan="4" style="border-bottom: 1px solid silver;">
            <label>Created On: <?php echo date("F j, Y, g:i a", strtotime( $research->getCreatedAt())); ?></label>
        </td>
    </tr>
     <tr>
         <?php if( $sf_user->isAuthenticated() && $research->getEntityId() == $sf_user->getAttribute('currentuser')->getId()): ?>
         <td width="20px" valign="top">
            <div>
            <?php if($research->isPrivacyType(Types::$RESEARCH_SCOPE[Types::$RESEARCH_SCOPE_PRIVATE])): ?>
                <img src="/images/icon/lock_icon.png" width="18" height="18" alt="private"/>
            <?php else: ?>
                <img src="/images/icon/unlock_icon.png" width="18" height="18" alt="private"/>
            <?php endif; ?>
            </div>

          </td>
            <?php endif; ?>
            <td class="tdPublicationDetailTitle" width="63%" valign="top">
            
            <div style="padding: 5px 0px">
            <a href="<?php echo url_for('publication/viewPublication?id='.$research->getId()); ?>"><span><?php echo $research["title"] ?></span></a>    
            </div>
            <div class="tdPublicationDetailCitation">
                <span><?php echo Structures_BibTex::bibToCite(htmlspecialchars_decode($research["citation"])) ?></span>
            </div>
            <?php if($research["abstract"]!=""): ?>
            <div class="tdPublicationDetailAbstract">
            <div id="tdabstract<?php echo $research["id"] ?>"><?php echo $research["abstract"] ?></div>
            <a id ="abstract<?php echo $research["id"] ?>" onclick="showAbstract(this.id);"><span align="left">read more++</span></a>
            </div>
            <?php endif ?>
            <?php if($research["remarks"]!=""): ?>
            <div class="tdPublicationDetailRemarks">
            <label>Remarks: </label><span><?php echo $research["remarks"] ?></span>
            </div>
            <?php endif ?>

        </td>
        <td width="4%"></td>

        <td class="tdPublicationDetailToolbar" valign="top">
         <div>
            
         </div>
       

          <table cellpadding="0" cellspacing="0">
             <?php if( $sf_user->isAuthenticated() && $sf_user->getAttribute('currentuser')->getEntitytyperefid() == Types::$ENT_TYPE[Types::$ENT_TYPE_PROFESSOR] && $selectedTab == Types::$RESEARCH_TABS[Types::$RESEARCH_TABS_PENDING_APPROVAL] ): ?>
              <tr>
             
                 <td class="approve">
                     <a class="clickable" onclick="setApprovalStatus(<?php echo $research->getId(); ?>, <?php echo Types::$RESEARCH_APPROVAL_STATUS[Types::$APPR_APPROVED]; ?>, 'hfSelectionStatus', <?php echo $sf_user->getAttribute('currentuser')->getId(); ?>);"><div>Approve</div></a>
                 </td>
                 <td class="reject">
                     <a class="clickable" onclick="setApprovalStatus(<?php echo $research->getId(); ?>, <?php echo Types::$RESEARCH_APPROVAL_STATUS[Types::$APPR_REVISION]; ?>, 'hfSelectionStatus', <?php echo $sf_user->getAttribute('currentuser')->getId(); ?>);"><div>Reject</div></a>
                 </td>
             </tr>
             <?php endif; ?>
             <tr>
                 <td class="download" valign="center">
                     <a id="<?php echo $research['id'] ?>" class="btnPublicationdownload"><div  align="left">Download Data</div></a>
                 </td>
                 <td class="visualization" valign="center">
                     <a onclick="loadResearchVisualization(<?php echo $research->getId(); ?>,'<?php echo $research->getTitle(); ?>')"><div  align="left">visualization</div></a>
                 </td>
             </tr>

             <tr>

                 <?php if($sf_user->isAuthenticated()): ?>
                     <?php if($research->getEntityid() == $sf_user->getAttribute('currentuser')->getId() || Researchgroup::isUserCollaboratingForThisResearch($sf_user->getAttribute('currentuser')->getId(), $research->getId())): ?>
                     <td class="editPaper" valign="center">
                         <a id="lnkEditPaper" href="<?php echo url_for('data/editResearch?id='.$research->getId()) ?>"><div  align="left">Edit Paper</div></a>
                     </td>
                     <?php endif; ?>

                     <?php if($research->getEntityid() == $sf_user->getAttribute('currentuser')->getId()): ?>
                     <td class="addUser" valign="center">
                         <a id="lnkAddUser" onclick="return loadNewCollaborativeUserDialog(20,400,false,'dlgAddUser_Home', <?php echo $research->getId(); ?>, 'txtRid');"><div  align="left">Add User</div></a>
                     </td>
                     <?php endif; ?>
                 <?php endif; ?>
             </tr>
             <tr>
                 <?php if($research["researchpaperurl"]!=""): ?>
                 <td class="link" valign="center">
                     <a href="<?php echo $research["researchpaperurl"] ?>" target="_blank"><div  align="left">View Paper</div></a>
                 </td>
                 <?php endif; ?>
             <tr>
         </table>
            <div class="tdPublicationDetailContributor" >
            <?php
                $researchStatus = '';
                switch($research->getApprovalstatustyperefid()) {
                    case Types::$RESEARCH_APPROVAL_STATUS[Types::$APPR_NEW]:
                        $researchStatus = '<span class="blueFont boldFont">NEW</span>';
                        break;
                    case Types::$RESEARCH_APPROVAL_STATUS[Types::$APPR_APPROVED]:
                        $researchStatus = '<span style="color: green;font-weight: bold">APPROVED</span> (By '.Entity::GetEntity($research->getApprovalauthorityid())->getFullname().')';
                        break;
                    case Types::$RESEARCH_APPROVAL_STATUS[Types::$APPR_REVIEWING]:
                        $researchStatus = '<span style="color: orange;font-weight: bold">REVIEWING</span>';
                        break;
                    case Types::$RESEARCH_APPROVAL_STATUS[Types::$APPR_AWAITING]:
                        $researchStatus = '<span style="color: orange;font-weight: bold">PENDING</span> (At '.Entity::GetEntity($research->getApprovalauthorityid())->getFullname().')';
                        break;
                    case Types::$RESEARCH_APPROVAL_STATUS[Types::$APPR_REVISION]:
                        $researchStatus = '<span style="color: orange;font-weight: bold">REVISION REQUIRED</span> (By '.Entity::GetEntity($research->getApprovalauthorityid())->getFullname().')';
                        break;
                }
            ?>
            <label>Status: <?php echo $researchStatus ?></label>
            </div>
            <div class="tdPublicationDetailContributor">
                <label>Contributor: </label><span><a href="<?php echo url_for('home/userProfile?id='.RBISUtility::encryptURLParamValue($research->getEntityid())); ?>"><?php echo Entity::GetEntity( $research->getEntityid())->getFullname(); ?></a></span>
            </div>
            <?php $totalCollaborators = $research->getResearchgroup()->count(); $tempIndex = 0; $appendComma = TRUE; ?>
            
            <div id="tdCollaboratorList_<?php echo $research->getId(); ?>" class="tdPublicationDetailContributor">
                <?php if($totalCollaborators > 0): ?>
                <label>Collaborator(s):</label>
                <?php /*
                       * If research belongs to current user then he/she should see all collaborats (PENDING/APPROVED)
                       * But if the current user is invitee then he/she should see his/her name after approval (NOT PENDING)
                       */
                ?>
                <?php foreach ($research->getCollaboratorList(array( Types::$COLLABORATION_REQUEST_STATUS[Types::$COLLABORATION_REQUEST_STATUS_REJECTED] ), TRUE) as $researchGroup): ?>
                    <?php $tempIndex++; ?>
                    <span>
                        <?php if($sf_user->isAuthenticated()): ?>
                            <?php if(($research->getEntityid() == $sf_user->getAttribute('currentuser')->getId())): ?>
                                <a href="<?php echo url_for('home/userProfile?id='.RBISUtility::encryptURLParamValue($researchGroup->getCollaborativeentityid())); ?>"><?php echo Entity::GetEntity( $researchGroup->getCollaborativeentityid())->getFullname(); ?></a>
                                <?php if($researchGroup->getCollaborationrequesttyperefid() == Types::$COLLABORATION_REQUEST_STATUS[Types::$COLLABORATION_REQUEST_STATUS_APPROVED]): ?>
                                    <a class="clickable" onclick="return removeCollaborativeUser(<?php echo $researchGroup->getCollaborativeentityid(); ?>, <?php echo $research->getId(); ?>);">(Remove)</a>
                                    <?php $appendComma = TRUE; ?>
                                <?php elseif($researchGroup->getCollaborationrequesttyperefid() == Types::$COLLABORATION_REQUEST_STATUS[Types::$COLLABORATION_REQUEST_STATUS_PENDING]): ?>
                                    (Pending/<a class="clickable" onclick="return removeCollaborativeUser(<?php echo $researchGroup->getCollaborativeentityid(); ?>, <?php echo $research->getId(); ?>);">Remove</a>)
                                    <?php $appendComma = TRUE; ?>
                                <?php endif; ?>
                            <?php elseif ($researchGroup->getCollaborativeentityid() == $sf_user->getAttribute('currentuser')->getId()): ?>
                                    <?php if($researchGroup->getCollaborationrequesttyperefid() == Types::$COLLABORATION_REQUEST_STATUS[Types::$COLLABORATION_REQUEST_STATUS_APPROVED]): ?>
                                        <a href="<?php echo url_for('home/userProfile?id='.RBISUtility::encryptURLParamValue($researchGroup->getCollaborativeentityid())); ?>"><?php echo Entity::GetEntity( $researchGroup->getCollaborativeentityid())->getFullname(); ?></a>
                                        <a class="clickable" onclick="return removeCollaborativeUser(<?php echo $researchGroup->getCollaborativeentityid(); ?>, <?php echo $research->getId(); ?>);">(Remove)</a>
                                        <?php $appendComma = TRUE; ?>
                                    <?php else: ?>
                                        <?php $appendComma = FALSE; ?>
                                    <?php endif; ?>
                            <?php else: ?>
                                    <a href="<?php echo url_for('home/userProfile?id='.RBISUtility::encryptURLParamValue($researchGroup->getCollaborativeentityid())); ?>"><?php echo Entity::GetEntity( $researchGroup->getCollaborativeentityid())->getFullname(); ?></a>
                            <?php endif; ?>
                        <?php else: ?>
                            <a href="<?php echo url_for('home/userProfile?id='.RBISUtility::encryptURLParamValue($researchGroup->getCollaborativeentityid())); ?>"><?php echo Entity::GetEntity( $researchGroup->getCollaborativeentityid())->getFullname(); ?></a>
                        <?php endif; ?>


                        <?php if($tempIndex < $totalCollaborators && $appendComma): ?>
                            <label>, </label>
                        <?php endif; ?>
                    </span>
                <?php endforeach; ?>
                <?php endif; ?>
            </div>
        </td>
    </tr>


</table>
 
<?php endforeach ?>
<div id="tdMore" style="width: 100%">
    <?php if($hasNextPage): ?>
        <?php if(!$sf_user->isAuthenticated()): ?>
            <a style="width: 100%" class="tdMore" onclick="return showMoreResearches(null, <?php echo Types::$RESEARCH_TABS[Types::$RESEARCH_TABS_ALL]; ?> , 0, 'hfSelectionStatus','hfPgNo', false);"><div> <?php echo ($researchList->count() - $researchList->getResults()->count()).' more' ?> </div></a>
        <?php else:?>
            <a style="width: 100%" class="tdMore" onclick="return showMoreResearches(null, document.getElementById('hfSelectionStatus').value,(document.getElementById('hfSelectionStatus').value == <?php echo Types::$RESEARCH_TABS[Types::$RESEARCH_TABS_ALL]; ?>? 0 : <?php echo $sf_user->getAttribute('currentuser')->getId(); ?>) , 'hfSelectionStatus','hfPgNo', false);"><div><?php echo ($researchList->count() - $researchList->getResults()->count()).' more' ?></div></a
        <?php endif ?>
    <?php endif; ?>
</div>

<input id="txtRid" type="hidden"/>
<div id="boxes">
    <div id="dlgAddUser_Home" class="window ui-dialog ui-widget ui-widget-content ui-corner-all">
        <div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">
            <span class="ui-dialog-title" id="ui-dialog-title-observation-form-dialog">Invite collaborator</span>
            <a onclick="javascript:$('.window').hide()" class="ui-dialog-titlebar-close ui-corner-all clickable" role="button">
                <span class="ui-icon ui-icon-closethick">close</span>
            </a>
        </div>
        <table cellpadding="0" cellspacing="0" width="100%" style="padding: 10px; font-size: 90%">
            <tr>
                <td id="imgAjaxLoading" colspan="2">&nbsp;</td>
            </tr>
            <tr id="trErrorMessage">
                <td colspan="2">&nbsp;</td>
            </tr>
            <tr>
                <td align="left" nowrap>
                    <span>User Name</span>
                </td>
                <td align="right">
                    <input style="width: 290px; padding: 3px;" type="text" id="txtMailTo" onclick="javascript:LoadUserList();" class="ui-autocomplete-input required text ui-widget-content ui-corner-all"/>
                </td>
            </tr>
            <tr>
                <td colspan="2">&nbsp;</td>
            </tr>
            <tr>
                <td align="center">
                    
                </td>
                <td align="right">
                    <button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" id="lnkAddUser" onclick="return addCollaborativeUser(document.getElementById('txtRid').value, $('#txtMailTo').val(), false);">
                        <span class="ui-button-text">Add User</span>
                    </button>
                    <button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" onclick="javascript:$('.window').hide();">
                        <span class="ui-button-text">Cancel</span>
                    </button>
                </td>
            </tr>
        </table>
    </div>
</div>

<div id="boxes">
<div id="divVisualization" class="window">asdasldhaskjdas</div>
<div id="mask"></div>
</div>